from treelib import Tree  #pip install treelib

def print_tree_with_indent(tree, node_id, indent=0):
    """
    Recursively prints the tree nodes with indentation to represent their depth.    
    :param tree: The Tree instance from treelib.
    :param node_id: The identifier of the current node.
    :param indent: Current indentation level.
    """
    node = tree[node_id]
    print(' ' * (indent * 2) + f"{node.tag} ({node.identifier})")
    
    children = tree.children(node_id)
    for child in children:
        print_tree_with_indent(tree, child.identifier, indent + 1)

# 创建一个Tree对象
tree = Tree()
tree.create_node("Root", "root")  # 根节点

# 添加子节点
tree.create_node("Child1", "1", parent="root")
tree.create_node("GrandChild1", "1.1", parent="1")
tree.create_node("GrandChild2", "1.2", parent="1")
tree.create_node("Child2", "2", parent="root")
tree.create_node("GrandChild1", "2.1", parent="2")
# 打印树结构
print_tree_with_indent(tree, "root")